package com.itheima.test03;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/*
TCP 的服务端 代码
接受客户端传来的 消息
同时给 客户端反馈

 */
public class ServerDemo {

    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9999);
        Socket socket = ss.accept();
        InputStream is = socket.getInputStream();
        //字节 -> 字符
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s;
        while ((s=reader.readLine())!=null){
            System.out.println(s);
        }
        //给客户端一个响应
        OutputStream os = socket.getOutputStream();

        //字符 -> 字节
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
        writer.write("瞅你咋地");
        writer.flush();
        //告诉 客户端 数据传输完毕了
       // socket.shutdownOutput();
        os.close();
        ss.close();

    }
}
